

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="深海火锅店">
  <meta name="keywords" content="">
  
    <meta name="description" content="基本配置源码在底部链接处  新建springcloud项目文件夹   直接用idea打开 springcloud文件夹（右键选择idea打开 或者 将文件夹拖到idea图标上）  新建两个springboot项目【user-service、order-service】  右键新建，选择module     同理新建order-service项目（步骤如上）  附：若某个项目没有被识别，找到该项目的">
<meta property="og:type" content="article">
<meta property="og:title" content="初识springcloud">
<meta property="og:url" content="http://example.com/2022/12/23/%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80/Java/%E5%AD%A6%E4%B9%A0/%E6%A1%86%E6%9E%B6/SpringCloud/day1/%E5%88%9D%E8%AF%86springcloud/%E5%88%9D%E8%AF%86springcloud/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="基本配置源码在底部链接处  新建springcloud项目文件夹   直接用idea打开 springcloud文件夹（右键选择idea打开 或者 将文件夹拖到idea图标上）  新建两个springboot项目【user-service、order-service】  右键新建，选择module     同理新建order-service项目（步骤如上）  附：若某个项目没有被识别，找到该项目的">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://gitee.com/tongstyle/blog-img/raw/master/img/202301201938111.png">
<meta property="og:image" content="https://gitee.com/tongstyle/blog-img/raw/master/img/202301201938936.png">
<meta property="og:image" content="https://gitee.com/tongstyle/blog-img/raw/master/img/202301201938972.png">
<meta property="og:image" content="https://gitee.com/tongstyle/blog-img/raw/master/img/202301201939197.png">
<meta property="og:image" content="https://gitee.com/tongstyle/blog-img/raw/master/img/202301201939919.png">
<meta property="og:image" content="https://gitee.com/tongstyle/blog-img/raw/master/img/202301201939327.png">
<meta property="og:image" content="https://gitee.com/tongstyle/blog-img/raw/master/img/202301201939799.png">
<meta property="og:image" content="https://gitee.com/tongstyle/blog-img/raw/master/img/202301201939256.png">
<meta property="og:image" content="https://gitee.com/tongstyle/blog-img/raw/master/img/202301201939028.png">
<meta property="og:image" content="https://gitee.com/tongstyle/blog-img/raw/master/img/202301201939697.png">
<meta property="og:image" content="https://gitee.com/tongstyle/blog-img/raw/master/img/202301201939559.png">
<meta property="og:image" content="https://gitee.com/tongstyle/blog-img/raw/master/img/202301201939923.png">
<meta property="og:image" content="https://gitee.com/tongstyle/blog-img/raw/master/img/202301201939927.png">
<meta property="og:image" content="https://gitee.com/tongstyle/blog-img/raw/master/img/202301201939521.png">
<meta property="og:image" content="https://gitee.com/tongstyle/blog-img/raw/master/img/202301201940658.png">
<meta property="og:image" content="https://gitee.com/tongstyle/blog-img/raw/master/img/202301201940506.png">
<meta property="article:published_time" content="2022-12-23T12:00:00.000Z">
<meta property="article:modified_time" content="2024-02-15T16:04:48.974Z">
<meta property="article:author" content="深海火锅店">
<meta property="article:tag" content="springcloud">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://gitee.com/tongstyle/blog-img/raw/master/img/202301201938111.png">
  
  
    <meta name="referrer" content="no-referrer-when-downgrade">
  
  
  <title>初识springcloud - Hexo</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.3","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.3.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>Fluid</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/background.jpg') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="初识springcloud"></span>
          
        </div>

        
          
  <div class="mt-3">
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2022-12-23 20:00" pubdate>
          2022年12月23日 晚上
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          14k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          114 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">初识springcloud</h1>
            
            
              <div class="markdown-body">
                
                <h2 id="基本配置"><a href="#基本配置" class="headerlink" title="基本配置"></a>基本配置</h2><p>源码在底部链接处</p>
<ol>
<li><p>新建springcloud项目文件夹</p>
<p><img src="https://gitee.com/tongstyle/blog-img/raw/master/img/202301201938111.png" srcset="/img/loading.gif" lazyload alt="1"></p>
</li>
<li><p>直接用idea打开 springcloud文件夹（右键选择idea打开 或者 将文件夹拖到idea图标上）</p>
</li>
<li><p>新建两个springboot项目【user-service、order-service】</p>
</li>
<li><p>右键新建，选择module</p>
<p><img src="https://gitee.com/tongstyle/blog-img/raw/master/img/202301201938936.png" srcset="/img/loading.gif" lazyload alt="2"></p>
<p><img src="https://gitee.com/tongstyle/blog-img/raw/master/img/202301201938972.png" srcset="/img/loading.gif" lazyload alt="3"></p>
<p><img src="https://gitee.com/tongstyle/blog-img/raw/master/img/202301201939197.png" srcset="/img/loading.gif" lazyload alt="4"></p>
</li>
<li><p>同理新建order-service项目（步骤如上）</p>
</li>
<li><p>附：<strong>若某个项目没有被识别</strong>，找到该项目的pom.xml，右键选择add as maven project即可</p>
<p><img src="https://gitee.com/tongstyle/blog-img/raw/master/img/202301201939919.png" srcset="/img/loading.gif" lazyload alt="11"></p>
</li>
<li><p>数据库准备</p>
<ul>
<li>新建两个<strong>数据库</strong>，分别是cloud-order、cloud-user</li>
<li>在各自的数据库上建表，这里就以一个表为例（tb_user、tb_order）</li>
<li>随意插入一些数据</li>
</ul>
<p><img src="https://gitee.com/tongstyle/blog-img/raw/master/img/202301201939327.png" srcset="/img/loading.gif" lazyload alt="5"></p>
<p><img src="https://gitee.com/tongstyle/blog-img/raw/master/img/202301201939799.png" srcset="/img/loading.gif" lazyload alt="6"></p>
</li>
<li><p>导入mybatis-plus的依赖、swagger的依赖以及mybatis-plus自动生成的依赖【两个项目都要导入这些依赖】</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-comment">&lt;!-- mybatis-plus --&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.baomidou<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>mybatis-plus-boot-starter<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>3.4.2<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br><span class="hljs-comment">&lt;!--新版 mybatis-plus 自动生成器--&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.baomidou<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>mybatis-plus-generator<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>3.5.2<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br><span class="hljs-comment">&lt;!-- freemarker --&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.freemarker<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>freemarker<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>2.3.31<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br><span class="hljs-comment">&lt;!--Swagger3.x--&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>io.springfox<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>springfox-boot-starter<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>3.0.0<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br></code></pre></td></tr></table></figure></li>
<li><p>编写mybatis-plus自动生成类</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> com.example.userservice;<br><br><span class="hljs-keyword">import</span> com.baomidou.mybatisplus.annotation.FieldFill;<br><span class="hljs-keyword">import</span> com.baomidou.mybatisplus.annotation.IdType;<br><span class="hljs-keyword">import</span> com.baomidou.mybatisplus.generator.FastAutoGenerator;<br><span class="hljs-keyword">import</span> com.baomidou.mybatisplus.generator.config.OutputFile;<br><span class="hljs-keyword">import</span> com.baomidou.mybatisplus.generator.config.rules.DateType;<br><span class="hljs-keyword">import</span> com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;<br><span class="hljs-keyword">import</span> com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;<br><span class="hljs-keyword">import</span> com.baomidou.mybatisplus.generator.fill.Column;<br><span class="hljs-keyword">import</span> com.baomidou.mybatisplus.generator.fill.Property;<br><br><span class="hljs-keyword">import</span> java.util.Collections;<br><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Generator</span> &#123;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> &#123;<br>        <span class="hljs-comment">//配置相关的数据库连接</span><br>        <span class="hljs-comment">// TODO TODO</span><br>        FastAutoGenerator.create(<span class="hljs-string">&quot;jdbc:mysql://localhost:3306/cloud-user?serverTimezone=Asia/Shanghai&quot;</span>, <span class="hljs-string">&quot;root&quot;</span>, <span class="hljs-string">&quot;root&quot;</span>)<br>                .globalConfig(builder -&gt; &#123;<br>                    builder.author(<span class="hljs-string">&quot;深海火锅店&quot;</span>) <span class="hljs-comment">// 设置作者</span><br>                            .enableSwagger() <span class="hljs-comment">// 开启 swagger 模式</span><br>                            .fileOverride() <span class="hljs-comment">// 覆盖已生成文件</span><br>                            <span class="hljs-comment">// TODO TODO</span><br>                            .outputDir(<span class="hljs-string">&quot;XXX\\Desktop\\springcloud\\user-service\\src\\main\\java\\&quot;</span>) <span class="hljs-comment">// 指定输出目录</span><br>                            .dateType(DateType.ONLY_DATE);<br>                &#125;)<br>                .packageConfig(builder -&gt; &#123;<br>                    <span class="hljs-comment">// TODO TODO</span><br>                    builder.parent(<span class="hljs-string">&quot;com.example.userservice&quot;</span>) <span class="hljs-comment">// 设置父包名</span><br><span class="hljs-comment">//                            .moduleName(&quot;&quot;) // 设置父包模块名</span><br>                            .entity(<span class="hljs-string">&quot;domain&quot;</span>)<br>                            .controller(<span class="hljs-string">&quot;controller&quot;</span>)<br>                            .mapper(<span class="hljs-string">&quot;mapper&quot;</span>)<br>                            .service(<span class="hljs-string">&quot;service&quot;</span>)<br>                            .serviceImpl(<span class="hljs-string">&quot;service.impl&quot;</span>)<br>                        	<span class="hljs-comment">// TODO TODO 写项目的路径</span><br>                            .pathInfo(Collections.singletonMap(OutputFile.xml, <span class="hljs-string">&quot;user-service\\src\\main\\resources\\mapper\\&quot;</span>)); <span class="hljs-comment">// 设置mapperXml生成路径</span><br>                &#125;)<br>                .strategyConfig(builder -&gt; &#123;<br>                    builder.addInclude(<span class="hljs-string">&quot;tb_user&quot;</span>)<span class="hljs-comment">// 设置需要生成的表名</span><br>                            <span class="hljs-comment">// TODO TODO</span><br>                            .addTablePrefix(<span class="hljs-string">&quot;tb_&quot;</span>) <span class="hljs-comment">// 设置过滤表前缀</span><br>                            .mapperBuilder()<br>                            <span class="hljs-comment">// 控制器controller配置</span><br>                            .controllerBuilder()<br>                            <span class="hljs-comment">// 开启生成@RestController 控制器</span><br>                            .enableRestStyle()<br>                            <span class="hljs-comment">// 开启驼峰转连字符</span><br>                            .enableHyphenStyle()<br>                            <span class="hljs-comment">// 开启父类</span><br><span class="hljs-comment">//                            .superClass(&quot;com.mybatisplus.generator.controller.BaseController&quot;)</span><br>                            <span class="hljs-comment">// 控制器统一后缀</span><br>                            .formatFileName(<span class="hljs-string">&quot;%sController&quot;</span>)<br><br>                            <span class="hljs-comment">// service配置</span><br>                            .serviceBuilder()<br>                            <span class="hljs-comment">// service统一后缀</span><br>                            .formatServiceFileName(<span class="hljs-string">&quot;%sService&quot;</span>)<br>                            <span class="hljs-comment">// serviceImpl统一后缀</span><br>                            .formatServiceImplFileName(<span class="hljs-string">&quot;%sServiceImpl&quot;</span>)<br><br>                            <span class="hljs-comment">//mapper配置</span><br>                            .mapperBuilder()<br>                            <span class="hljs-comment">// 生成基础字段的map映射map</span><br>                            .enableBaseResultMap()<br>                            <span class="hljs-comment">// 生成基础查询的sql</span><br>                            .enableBaseColumnList()<br><br>                            <span class="hljs-comment">// 实体类配置</span><br>                            .entityBuilder()<br>                            <span class="hljs-comment">// 开启链式模型，开启lombok模型不需要开启这个</span><br><span class="hljs-comment">//                            .enableChainModel()</span><br>                            <span class="hljs-comment">// 开启lombok模型</span><br>                            .enableLombok()<br>                            <span class="hljs-comment">// 开启表字段注解</span><br>                            .enableTableFieldAnnotation()<br>                            <span class="hljs-comment">// 逻辑删除字段</span><br>                            <span class="hljs-comment">// TODO TODO</span><br>                            <span class="hljs-comment">//.logicDeleteColumnName(&quot;is_deleted&quot;)</span><br>                            <span class="hljs-comment">// 数据库表映射到实体的命名策略</span><br>                            .naming(NamingStrategy.underline_to_camel)<br>                            <span class="hljs-comment">// 数据库表字段映射到实体的命名策略,驼峰命名，这个未设置会按照naming来配置</span><br><span class="hljs-comment">//                            .columnNaming(NamingStrategy.underline_to_camel)</span><br>                            <span class="hljs-comment">// 指定实体类父类</span><br><span class="hljs-comment">//                            .superClass(&quot;com.mybatisplus.generator.entity.BaseEntity&quot;)</span><br>                            <span class="hljs-comment">// 父类字段</span><br><span class="hljs-comment">//                            .addSuperEntityColumns(&quot;id&quot;, &quot;create_id&quot;, &quot;modify_id&quot;, &quot;create_date&quot;, &quot;modify_date&quot;, &quot;is_deleted&quot;)</span><br><span class="hljs-comment">//                             开启 ActiveRecord 模式，即实体类继承Model类,自己提供CRUD操作,不建议使用,会和父类形成单继承冲突</span><br><span class="hljs-comment">//                            .enableActiveRecord()</span><br>                            <span class="hljs-comment">// 表字段填充字段，对应数据库字段，插入的时候自动填充</span><br>                            .addTableFills(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Column</span>(<span class="hljs-string">&quot;create_date&quot;</span>, FieldFill.INSERT))<br>                            <span class="hljs-comment">// 表字段填充字段，对应实体类字段，插入的时候自动填充</span><br>                            .addTableFills(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Property</span>(<span class="hljs-string">&quot;createDate&quot;</span>, FieldFill.INSERT))<br>                            <span class="hljs-comment">// 表字段填充字段，对应数据库字段，更新的时候自动填充</span><br>                            .addTableFills(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Column</span>(<span class="hljs-string">&quot;modify_date&quot;</span>, FieldFill.UPDATE))<br>                            <span class="hljs-comment">// 表字段填充字段，对应实体类字段，更新的时候自动填充</span><br>                            .addTableFills(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Property</span>(<span class="hljs-string">&quot;modifyDate&quot;</span>, FieldFill.UPDATE))<br>                            <span class="hljs-comment">// 忽略的字段</span><br><span class="hljs-comment">//                            .addIgnoreColumns(&quot;version&quot;)</span><br>                            <span class="hljs-comment">// id自增</span><br>                            .idType(IdType.AUTO);<br>                    <span class="hljs-comment">// 实体类统一后缀</span><br>                &#125;)<br>                .templateEngine(<span class="hljs-keyword">new</span> <span class="hljs-title class_">FreemarkerTemplateEngine</span>()) <span class="hljs-comment">// 使用Freemarker引擎模板，默认的是Velocity引擎模板</span><br>                .execute();<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p><strong>注意</strong>:以上写了&#x2F;&#x2F; TODO的地方都需要注意</p>
<ol>
<li>数据库的连接</li>
<li>项目的地址</li>
<li>项目的名称</li>
<li>xml文件的路径，名称要改</li>
<li>表过滤前缀</li>
<li>逻辑删除字段（表中没有这个字段，可以注释掉）</li>
</ol>
</li>
<li><p>运行main方法后自动生成，结构如下</p>
<p><img src="https://gitee.com/tongstyle/blog-img/raw/master/img/202301201939256.png" srcset="/img/loading.gif" lazyload alt="7"></p>
<p>order同理生成（略）</p>
<p>建议在Generator内直接ctrl+f搜索user关键词，改为order即可</p>
</li>
<li><p>先简单写个get方法来测试一下</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// ordercontroller</span><br><span class="hljs-meta">@RestController</span><br><span class="hljs-meta">@RequestMapping(&quot;/order&quot;)</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">OrderController</span> &#123;<br>    <span class="hljs-meta">@Autowired</span><br>    <span class="hljs-keyword">private</span> OrderService orderService;<br><br>    <span class="hljs-meta">@GetMapping(&quot;/&#123;id&#125;&quot;)</span><br>    <span class="hljs-keyword">private</span> Object <span class="hljs-title function_">getOrder</span><span class="hljs-params">(<span class="hljs-meta">@PathVariable(&quot;id&quot;)</span> Long id)</span>&#123;<br>        <span class="hljs-keyword">return</span> orderService.getById(id);<br>    &#125;<br><br>&#125;<br><br><span class="hljs-comment">// usercontroller</span><br><span class="hljs-meta">@RestController</span><br><span class="hljs-meta">@RequestMapping(&quot;/user&quot;)</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">UserController</span> &#123;<br>    <span class="hljs-meta">@Autowired</span><br>    <span class="hljs-keyword">private</span> UserService userService;<br><br>    <span class="hljs-meta">@GetMapping(&quot;/&#123;id&#125;&quot;)</span><br>    <span class="hljs-keyword">public</span> Object <span class="hljs-title function_">getUser</span><span class="hljs-params">(<span class="hljs-meta">@PathVariable(&quot;id&quot;)</span> Long id)</span>&#123;<br>        <span class="hljs-keyword">return</span> userService.getById(id);<br>    &#125;<br><br>&#125;<br></code></pre></td></tr></table></figure></li>
<li><p>order启动类上加入@MapperScan注解【OrderServiceApplication】—-user同理</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> com.example.orderservice;<br><br><span class="hljs-keyword">import</span> org.mybatis.spring.annotation.MapperScan;<br><span class="hljs-keyword">import</span> org.springframework.boot.SpringApplication;<br><span class="hljs-keyword">import</span> org.springframework.boot.autoconfigure.SpringBootApplication;<br><br><span class="hljs-meta">@SpringBootApplication</span><br><span class="hljs-meta">@MapperScan(&quot;com.example.orderservice.mapper&quot;)</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">OrderServiceApplication</span> &#123;<br><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> &#123;<br>        SpringApplication.run(OrderServiceApplication.class, args);<br>    &#125;<br><br>&#125;<br></code></pre></td></tr></table></figure></li>
<li><p>配置application.properties【两个项目】</p>
<p>【user】</p>
<figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><code class="hljs properties"><span class="hljs-comment"># 应用名称</span><br><span class="hljs-attr">spring.application.name</span>=<span class="hljs-string">user-service</span><br><span class="hljs-comment"># 应用服务 WEB 访问端口</span><br><span class="hljs-attr">server.port</span>=<span class="hljs-string">8081</span><br><span class="hljs-comment"># 数据库驱动：</span><br><span class="hljs-attr">spring.datasource.driver-class-name</span>=<span class="hljs-string">com.mysql.cj.jdbc.Driver</span><br><span class="hljs-comment"># 数据源名称</span><br><span class="hljs-attr">spring.datasource.name</span>=<span class="hljs-string">defaultDataSource</span><br><span class="hljs-comment"># 数据库连接地址</span><br><span class="hljs-attr">spring.datasource.url</span>=<span class="hljs-string">jdbc:mysql://localhost:3306/cloud-user?serverTimezone=UTC</span><br><span class="hljs-comment"># 数据库用户名&amp;密码：</span><br><span class="hljs-attr">spring.datasource.username</span>=<span class="hljs-string">root</span><br><span class="hljs-attr">spring.datasource.password</span>=<span class="hljs-string">123456</span><br><span class="hljs-comment"># 配置mybatis-plus 打印sql日志</span><br><span class="hljs-attr">mybatis-plus.configuration.log-impl</span>=<span class="hljs-string">org.apache.ibatis.logging.stdout.StdOutImpl</span><br><span class="hljs-comment"></span><br><span class="hljs-comment"># xml文件路径</span><br><span class="hljs-attr">mybatis-plus.mapper-locations</span>=<span class="hljs-string">classpath:/mapper/**/*.xml</span><br><span class="hljs-comment"></span><br><span class="hljs-comment"># 配置最新全局配置文件</span><br><span class="hljs-comment">#mybatis-plus.config-location=classpath:mybatis-config.xml</span><br><span class="hljs-comment"></span><br><span class="hljs-comment"># 配置mybatis-plus 包路径</span><br><span class="hljs-attr">mybatis-plus.type-aliases-package</span>=<span class="hljs-string">com.example.userservice.domain</span><br><span class="hljs-comment"></span><br><span class="hljs-comment"># mybatis-plus下划线转驼峰配置，默认为true</span><br><span class="hljs-attr">mybatis-plus.configuration.map-underscore-to-camel-case</span>=<span class="hljs-string">true</span><br><span class="hljs-comment"></span><br><span class="hljs-comment"># 配置全局默认主键类型，实体类不用加@TableId(value =&quot;id&quot;,type = IdType.AUTO)</span><br><span class="hljs-attr">mybatis-plus.global-config.db-config.id-type</span>=<span class="hljs-string">auto</span><br><span class="hljs-comment"></span><br><span class="hljs-comment"># 逻辑删除 （1为删除，0为未删除）</span><br><span class="hljs-comment">#mybatis-plus.global-config.db-config.logic-delete-value=1</span><br><span class="hljs-comment">#mybatis-plus.global-config.db-config.logic-not-delete-value=0</span><br><span class="hljs-comment"></span><br><span class="hljs-comment"># 如果java实体类没加注解@TableLogic，则可以配置这个，推介这里配置</span><br><span class="hljs-comment">#mybatis-plus.global-config.db-config.logic-delete-field=is_deleted</span><br><span class="hljs-comment"></span><br><span class="hljs-comment"># ==========自定义swagger配置==========</span><br><span class="hljs-attr">swagger.enable</span>=<span class="hljs-string">true</span><br><span class="hljs-attr">swagger.application-name</span>=<span class="hljs-string">$&#123;spring.application.name&#125;</span><br><span class="hljs-attr">swagger.application-version</span>=<span class="hljs-string">1.0</span><br><span class="hljs-comment">#swagger.application-description=1024shop电商平台管理后端接口文档</span><br><span class="hljs-attr">swagger.application-description</span>=<span class="hljs-string">user</span><br><span class="hljs-comment"># swagger3</span><br><span class="hljs-attr">spring.mvc.pathmatch.matching-strategy</span>=<span class="hljs-string">ant_path_matcher</span><br><br></code></pre></td></tr></table></figure>

<p>【order】</p>
<figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><code class="hljs properties"><span class="hljs-comment"># 应用名称</span><br><span class="hljs-attr">spring.application.name</span>=<span class="hljs-string">order-service</span><br><span class="hljs-comment"># 应用服务 WEB 访问端口</span><br><span class="hljs-attr">server.port</span>=<span class="hljs-string">8082</span><br><span class="hljs-comment"># 数据库驱动：</span><br><span class="hljs-attr">spring.datasource.driver-class-name</span>=<span class="hljs-string">com.mysql.cj.jdbc.Driver</span><br><span class="hljs-comment"># 数据源名称</span><br><span class="hljs-attr">spring.datasource.name</span>=<span class="hljs-string">defaultDataSource</span><br><span class="hljs-comment"># 数据库连接地址</span><br><span class="hljs-attr">spring.datasource.url</span>=<span class="hljs-string">jdbc:mysql://localhost:3306/cloud-order?serverTimezone=UTC</span><br><span class="hljs-comment"># 数据库用户名&amp;密码：</span><br><span class="hljs-attr">spring.datasource.username</span>=<span class="hljs-string">root</span><br><span class="hljs-attr">spring.datasource.password</span>=<span class="hljs-string">123456</span><br><span class="hljs-comment"># 配置mybatis-plus 打印sql日志</span><br><span class="hljs-attr">mybatis-plus.configuration.log-impl</span>=<span class="hljs-string">org.apache.ibatis.logging.stdout.StdOutImpl</span><br><span class="hljs-comment"></span><br><span class="hljs-comment"># xml文件路径</span><br><span class="hljs-attr">mybatis-plus.mapper-locations</span>=<span class="hljs-string">classpath:/mapper/**/*.xml</span><br><span class="hljs-comment"></span><br><span class="hljs-comment"># 配置最新全局配置文件</span><br><span class="hljs-comment">#mybatis-plus.config-location=classpath:mybatis-config.xml</span><br><span class="hljs-comment"></span><br><span class="hljs-comment"># 配置mybatis-plus 包路径</span><br><span class="hljs-attr">mybatis-plus.type-aliases-package</span>=<span class="hljs-string">com.example.orderservice.domain</span><br><span class="hljs-comment"></span><br><span class="hljs-comment"># mybatis-plus下划线转驼峰配置，默认为true</span><br><span class="hljs-attr">mybatis-plus.configuration.map-underscore-to-camel-case</span>=<span class="hljs-string">true</span><br><span class="hljs-comment"></span><br><span class="hljs-comment"># 配置全局默认主键类型，实体类不用加@TableId(value =&quot;id&quot;,type = IdType.AUTO)</span><br><span class="hljs-attr">mybatis-plus.global-config.db-config.id-type</span>=<span class="hljs-string">auto</span><br><span class="hljs-comment"></span><br><span class="hljs-comment"># 逻辑删除 （1为删除，0为未删除）</span><br><span class="hljs-comment">#mybatis-plus.global-config.db-config.logic-delete-value=1</span><br><span class="hljs-comment">#mybatis-plus.global-config.db-config.logic-not-delete-value=0</span><br><span class="hljs-comment"></span><br><span class="hljs-comment"># 如果java实体类没加注解@TableLogic，则可以配置这个，推介这里配置</span><br><span class="hljs-comment">#mybatis-plus.global-config.db-config.logic-delete-field=is_deleted</span><br><span class="hljs-comment"></span><br><span class="hljs-comment"># ==========自定义swagger配置==========</span><br><span class="hljs-attr">swagger.enable</span>=<span class="hljs-string">true</span><br><span class="hljs-attr">swagger.application-name</span>=<span class="hljs-string">$&#123;spring.application.name&#125;</span><br><span class="hljs-attr">swagger.application-version</span>=<span class="hljs-string">1.0</span><br><br><span class="hljs-attr">swagger.application-description</span>=<span class="hljs-string">order</span><br><span class="hljs-comment"># swagger3</span><br><span class="hljs-attr">spring.mvc.pathmatch.matching-strategy</span>=<span class="hljs-string">ant_path_matcher</span><br></code></pre></td></tr></table></figure></li>
<li><p>复制一份pom.xml到springcloud根目录进行修改</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-meta">&lt;?xml version=<span class="hljs-string">&quot;1.0&quot;</span> encoding=<span class="hljs-string">&quot;UTF-8&quot;</span>?&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">project</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">&quot;http://maven.apache.org/POM/4.0.0&quot;</span> <span class="hljs-attr">xmlns:xsi</span>=<span class="hljs-string">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span><br><span class="hljs-tag">         <span class="hljs-attr">xsi:schemaLocation</span>=<span class="hljs-string">&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">modelVersion</span>&gt;</span>4.0.0<span class="hljs-tag">&lt;/<span class="hljs-name">modelVersion</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">parent</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-starter-parent<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>2.7.6<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">relativePath</span>/&gt;</span> <span class="hljs-comment">&lt;!-- lookup parent from repository --&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">parent</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.example<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>springcloud<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.0<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">description</span>&gt;</span>springcloud项目<span class="hljs-tag">&lt;/<span class="hljs-name">description</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">properties</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">java.version</span>&gt;</span>1.8<span class="hljs-tag">&lt;/<span class="hljs-name">java.version</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">properties</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">modules</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">module</span>&gt;</span>order-service<span class="hljs-tag">&lt;/<span class="hljs-name">module</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">module</span>&gt;</span>user-service<span class="hljs-tag">&lt;/<span class="hljs-name">module</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">modules</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">packaging</span>&gt;</span>pom<span class="hljs-tag">&lt;/<span class="hljs-name">packaging</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">project</span>&gt;</span><br><br></code></pre></td></tr></table></figure>

<p><img src="https://gitee.com/tongstyle/blog-img/raw/master/img/202301201939028.png" srcset="/img/loading.gif" lazyload alt="12"></p>
</li>
<li><p>运行项目，测试</p>
<ul>
<li><p><a target="_blank" rel="noopener" href="http://localhost:8081/user/1">http://localhost:8081/user/1</a> 测试用户模块</p>
<p><img src="https://gitee.com/tongstyle/blog-img/raw/master/img/202301201939697.png" srcset="/img/loading.gif" lazyload alt="8"></p>
</li>
<li><p><a target="_blank" rel="noopener" href="http://localhost:8082/order/1">http://localhost:8082/order/1</a> 测试订单模块</p>
<p><img src="https://gitee.com/tongstyle/blog-img/raw/master/img/202301201939559.png" srcset="/img/loading.gif" lazyload alt="9"></p>
</li>
</ul>
</li>
<li><p>swagger配置【不需要swagger则可省略】</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@Component</span><br><span class="hljs-meta">@Data</span><br><span class="hljs-meta">@ConfigurationProperties(&quot;swagger&quot;)</span> <span class="hljs-comment">// 映射到properties配置，省略前缀</span><br><span class="hljs-meta">@EnableOpenApi</span> <span class="hljs-comment">// 开启规范</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">SwaggerConfiguration</span> &#123;<br>    <span class="hljs-comment">/**</span><br><span class="hljs-comment">     * 是否开启swagger，生产环境一般关闭，所以这里定义一个变量</span><br><span class="hljs-comment">     */</span><br>    <span class="hljs-keyword">private</span> Boolean enable;<br>    <span class="hljs-comment">/**</span><br><span class="hljs-comment">     * 项目应用名</span><br><span class="hljs-comment">     */</span><br>    <span class="hljs-keyword">private</span> String applicationName;<br>    <span class="hljs-comment">/**</span><br><span class="hljs-comment">     * 项目版本信息</span><br><span class="hljs-comment">     */</span><br>    <span class="hljs-keyword">private</span> String applicationVersion;<br>    <span class="hljs-comment">/**</span><br><span class="hljs-comment">     * 项目描述信息</span><br><span class="hljs-comment">     */</span><br>    <span class="hljs-keyword">private</span> String applicationDescription;<br>    <span class="hljs-meta">@Bean</span><br>    <span class="hljs-keyword">public</span> Docket <span class="hljs-title function_">docket</span><span class="hljs-params">()</span> &#123;<br>        <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Docket</span>(DocumentationType.OAS_30)<br>                .pathMapping(<span class="hljs-string">&quot;/&quot;</span>)<br>                <span class="hljs-comment">// 定义是否开启swagger，false为关闭，可以通过变量控制，线上关闭</span><br>                .enable(enable)<br>                <span class="hljs-comment">//配置api文档元信息</span><br>                .apiInfo(apiInfo())<br>                <span class="hljs-comment">// 选择哪些接口作为swagger的doc发布</span><br>                .select()<br>                <span class="hljs-comment">//apis() 控制哪些接口暴露给swagger，</span><br>                <span class="hljs-comment">// RequestHandlerSelectors.any() 所有都暴露</span><br>                <span class="hljs-comment">// RequestHandlerSelectors.basePackage(&quot;net.xdclass.*&quot;)  指定包位置</span><br>                <span class="hljs-comment">// withMethodAnnotation(ApiOperation.class)标记有这个注解 ApiOperation</span><br>                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))<br>                .paths(PathSelectors.any())<br>                .build();<br>    &#125;<br>    <span class="hljs-keyword">private</span> ApiInfo <span class="hljs-title function_">apiInfo</span><span class="hljs-params">()</span> &#123;<br>        <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">ApiInfoBuilder</span>()<br>                .title(applicationName)<br>                .description(applicationDescription)<br>                .contact(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Contact</span>(<span class="hljs-string">&quot;深海火锅店&quot;</span>, <span class="hljs-string">&quot;tongstyle.gitee.io&quot;</span>, <span class="hljs-string">&quot;938798576@aliyun.com&quot;</span>))<br>                .version(applicationVersion)<br>                .build();<br>    &#125;<br><br>&#125;<br></code></pre></td></tr></table></figure>

<p><img src="https://gitee.com/tongstyle/blog-img/raw/master/img/202301201939923.png" srcset="/img/loading.gif" lazyload alt="10"></p>
<p>order模块同理配置</p>
<p>在controller中添加注解，在类上添加@Api注解，在方法上添加@ApiOperation(“description”)注解</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@RestController</span><br><span class="hljs-meta">@RequestMapping(&quot;/order&quot;)</span><br><span class="hljs-meta">@Api</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">OrderController</span> &#123;<br>    <span class="hljs-meta">@Autowired</span><br>    <span class="hljs-keyword">private</span> OrderService orderService;<br><br>    <span class="hljs-meta">@GetMapping(&quot;/&#123;id&#125;&quot;)</span><br>    <span class="hljs-meta">@ApiOperation(&quot;查找用户&quot;)</span><br>    <span class="hljs-keyword">private</span> Object <span class="hljs-title function_">getOrder</span><span class="hljs-params">(<span class="hljs-meta">@PathVariable(&quot;id&quot;)</span> Long id)</span>&#123;<br>        <span class="hljs-keyword">return</span> orderService.getById(id);<br>    &#125;<br><br>&#125;<br></code></pre></td></tr></table></figure>

<p>order模块同理配置</p>
</li>
</ol>
<h2 id="服务调用"><a href="#服务调用" class="headerlink" title="服务调用"></a>服务调用</h2><p>在order模块中调用user的方法【在订单中查找用户的信息】</p>
<p>在order模块中导入user模块的依赖</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.example<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>user-service<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>0.0.1-SNAPSHOT<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">scope</span>&gt;</span>compile<span class="hljs-tag">&lt;/<span class="hljs-name">scope</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br></code></pre></td></tr></table></figure>

<p>在Order实体类中添加如下属性</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@ApiModelProperty(&quot;用户信息&quot;)</span><br><span class="hljs-meta">@TableField(exist = false)</span><br><span class="hljs-keyword">private</span> User user;<br></code></pre></td></tr></table></figure>

<p>在order启动类OrderServiceApplication中添加如下方法</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@Bean</span><br><span class="hljs-keyword">public</span> RestTemplate <span class="hljs-title function_">restTemplate</span><span class="hljs-params">()</span> &#123;<br>	<span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">RestTemplate</span>();<br>&#125;<br></code></pre></td></tr></table></figure>

<p>在orderservice中添加如下方法</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs java">Order <span class="hljs-title function_">queryOrderById</span><span class="hljs-params">(Long orderId)</span>;<br></code></pre></td></tr></table></figure>

<p>并在impl里重写该方法</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@Override</span><br><span class="hljs-keyword">public</span> Order <span class="hljs-title function_">queryOrderById</span><span class="hljs-params">(Long orderId)</span>&#123;<br>    <span class="hljs-type">Order</span> <span class="hljs-variable">order</span> <span class="hljs-operator">=</span> baseMapper.selectById(orderId);<br>    String url=<span class="hljs-string">&quot;http://localhost:8081/user/&quot;</span>+order.getUserId();<br>    <span class="hljs-type">User</span> <span class="hljs-variable">forObject</span> <span class="hljs-operator">=</span> restTemplate.getForObject(url, User.class);<br>    order.setUser(forObject);<br>    <span class="hljs-keyword">return</span> order;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>更改OrderController代码</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@GetMapping(&quot;/&#123;id&#125;&quot;)</span><br><span class="hljs-meta">@ApiOperation(&quot;查找订单&quot;)</span><br><span class="hljs-keyword">private</span> Object <span class="hljs-title function_">getOrder</span><span class="hljs-params">(<span class="hljs-meta">@PathVariable(&quot;id&quot;)</span> Long id)</span>&#123;<br>    <span class="hljs-keyword">return</span> orderService.queryOrderById(id);<br>&#125;<br></code></pre></td></tr></table></figure>

<p><img src="https://gitee.com/tongstyle/blog-img/raw/master/img/202301201939927.png" srcset="/img/loading.gif" lazyload alt="13"></p>
<p>当然，不添加User依赖，直接在order新建一个user实体类其实也可以</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@Data</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">User</span> &#123;<br>    <span class="hljs-keyword">private</span> Long id;<br>    <span class="hljs-keyword">private</span> String username;<br>    <span class="hljs-keyword">private</span> String address;<br>&#125;<br></code></pre></td></tr></table></figure>

<p><strong>但是有一个非常严重的问题</strong>：以上实现的业务是根据订单查用户，如果还需要根据用户查订单的话，那么在用户模块继续导入订单模块就会形成一个问题，模块与模块之间的相互依赖关系</p>
<p>源码：</p>
<p>链接：<a target="_blank" rel="noopener" href="https://pan.baidu.com/s/1FAVIVz92EwvNkGoMxIvMTQ?pwd=s1v5">https://pan.baidu.com/s/1FAVIVz92EwvNkGoMxIvMTQ?pwd=s1v5</a><br>提取码：s1v5</p>
<h2 id="更正"><a href="#更正" class="headerlink" title="更正"></a>更正</h2><p>之前一直没懂教程里是怎么在order服务里使用user服务的实体类的，起初我以为是上述写法，在order服务里引入了user服务的依赖，但是教程的代码里并没有引入user的依赖，所以我一直很疑惑。</p>
<p>难道是在order服务里直接写了一个user实体类？这不太优雅啊！而且…教程的代码里依然没有在order服务里找到user实体类。。。</p>
<p>视频看了几遍，找到了一个切入点…</p>
<p><img src="https://gitee.com/tongstyle/blog-img/raw/master/img/202301201939521.png" srcset="/img/loading.gif" lazyload alt="14"></p>
<p>没有导入其他的包，所以…应该是在pojo里写了一个user实体类了，至于为什么给的代码里没在order里找到user实体类…<br>我只能解释为后期删掉了</p>
<p>其他的一样写，依然能实现上述效果</p>
<p><img src="https://gitee.com/tongstyle/blog-img/raw/master/img/202301201940658.png" srcset="/img/loading.gif" lazyload alt="15"></p>
<p><img src="https://gitee.com/tongstyle/blog-img/raw/master/img/202301201940506.png" srcset="/img/loading.gif" lazyload alt="16"></p>
<p>链接：<a target="_blank" rel="noopener" href="https://pan.baidu.com/s/1WerXmr-Ntp5rwhTVLMXOWQ?pwd=b75y">https://pan.baidu.com/s/1WerXmr-Ntp5rwhTVLMXOWQ?pwd=b75y</a><br>提取码：b75y<br>–来自百度网盘超级会员V3的分享</p>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/springcloud/" class="category-chain-item">springcloud</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/springcloud/">#springcloud</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>初识springcloud</div>
      <div>http://example.com/2022/12/23/编程语言/Java/学习/框架/SpringCloud/day1/初识springcloud/初识springcloud/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>深海火锅店</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2022年12月23日</div>
        </div>
      
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2022/12/23/%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80/Java/%E5%AD%A6%E4%B9%A0/%E6%A1%86%E6%9E%B6/SpringCloud/day1/eureka%E6%9C%8D%E5%8A%A1%E6%B3%A8%E5%86%8C/Eureka%E6%B3%A8%E5%86%8C%E4%B8%AD%E5%BF%83/" title="Eureka+Ribbon+Nacos">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Eureka+Ribbon+Nacos</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2022/12/23/%E6%95%B0%E6%8D%AE%E5%BA%93/MySQL/%E5%A4%A7%E6%95%B0%E6%8D%AE%E5%AD%A6%E4%B9%A0/DB10&amp;DB11/DB11_%E6%95%B0%E6%8D%AE%E5%BA%93%E5%88%86%E7%BB%84%E4%B8%8E%E6%8E%92%E5%BA%8F/" title="DB11_数据库分组与排序">
                        <span class="hidden-mobile">DB11_数据库分组与排序</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
    <div class="statistics">
  
  

  
    
      <span id="busuanzi_container_site_pv" style="display: none">
        总访问量 
        <span id="busuanzi_value_site_pv"></span>
         次
      </span>
    
    
      <span id="busuanzi_container_site_uv" style="display: none">
        总访客数 
        <span id="busuanzi_value_site_uv"></span>
         人
      </span>
    
    
  
</div>

  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>

  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>




  
<script src="//cdn.jsdelivr.net/gh/EmoryHuang/BlogBeautify@1.1/DynamicRibbon.min.js"></script>



<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
